package com.eliza.springboot.v3.http.control.webFlux

import com.eliza.springboot.v3.repository.entity.Song
import com.eliza.springboot.v3.repository.repo.postgresql.SongRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.*

@RestController()
@RequestMapping("/database")
class RespDatabase {
    @Autowired
    private lateinit var songRepository: SongRepository

    @RequestMapping("/findAll")
    fun database(): ResponseEntity<Page<Song>> {
        return ResponseEntity.ok(songRepository.findAll(PageRequest.of(0, 10)))
    }

    @RequestMapping("/getById/{id}")
    fun pathVariable(@PathVariable id: Long): ResponseEntity<Optional<Song>> {
        println("id:${id}")
        return ResponseEntity.ok(songRepository.findById(id))
    }
}